package ren.kane.phoenix.util.tree;

import com.google.common.base.MoreObjects;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 树节点实体类.
 *
 * @author renrk(1275) on 2019-03-01 9:42 AM
 **/
public class TreeNode<T extends TreeNode<T>> {

    private String id;

    private String parentId;
    // 是否根节点
    private boolean isRootNode = false;
    // 是否叶子节点
    private boolean isLeafNode = false;
    // 所有子节点列表
    private List<T> children = new ArrayList<>();
    // 所有下级节点的id集合
    private Set<String> juniorIds = new HashSet<>();
    // 所有下级叶子节点id集合
    private Set<String> leafNodeIds = new HashSet<>();
    // 面包屑路径
    private String breadCrumb;

    public TreeNode() {
    }

    public String getId() {
        return id;
    }

    public String getParentId() {
        return parentId;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public boolean isRootNode() {
        return isRootNode;
    }

    public void setRootNode(boolean rootNode) {
        isRootNode = rootNode;
    }

    public boolean isLeafNode() {
        return isLeafNode;
    }

    public void setLeafNode(boolean leafNode) {
        isLeafNode = leafNode;
    }

    public List<T> getChildren() {
        return children;
    }

    public void setChildren(List<T> children) {
        this.children = children;
    }

    public Set<String> getJuniorIds() {
        return juniorIds;
    }

    public void setJuniorIds(Set<String> juniorIds) {
        this.juniorIds = juniorIds;
    }

    public Set<String> getLeafNodeIds() {
        return leafNodeIds;
    }

    public void setLeafNodeIds(Set<String> leafNodeIds) {
        this.leafNodeIds = leafNodeIds;
    }

    public String getBreadCrumb() {
        return breadCrumb;
    }

    public void setBreadCrumb(String breadCrumb) {
        this.breadCrumb = breadCrumb;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
            .add("id", id)
            .add("parentId", parentId)
            .add("isRoot", isRootNode)
            .add("isLeaf", isLeafNode)
            .add("children", children)
            .add("juniorId", juniorIds)
            .add("leafNodeId", leafNodeIds)
            .add("breadCrumb", breadCrumb)
            .toString();
    }
}
